package com.u2b.business.activity;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.u2b.beans.Activity;
import com.u2b.beans.Comment;
import com.u2b.beans.User;
import com.u2b.business.location.DistanceService;
import com.u2b.business.net.FileUpload;
import com.u2b.business.time.TimeService;
import com.u2b.db.activity.ActivityDaoImpl;
import com.u2b.db.datasource.MyBeanUtils;
import com.u2b.global.utils.Constants;
import com.u2b.servlet.utils.ParameterParser;

public class ActivityService
{
    private final TimeService timeProxy;
    private final ActivityDaoImpl adip;
    private final FileUpload fileUpload;
    private final MyBeanUtils beanUtils;
    private final DistanceService distanceService;
    public ActivityService()
    {
        adip = new ActivityDaoImpl();
        timeProxy = new TimeService();
       distanceService=new DistanceService();
        fileUpload = new FileUpload();
        beanUtils = new MyBeanUtils();

    }

    public int createActivity(HttpServletRequest request, String[] textParams)
    {
        String[] urlNames = new String[]
        { "photo_URL", "audio_URL", "video_URL" };
        HashMap<String, Object> value = fileUpload.Upload(request, textParams, new String[]
        { ".jpg", ".amr", ".3gp" }, urlNames, "activity");
        timeProxy.addCreateTime(value);
        distanceService.addGeoHash(value);
        int primaryKey = adip.createActivity(value);
        return primaryKey;

    }

    public int joinThis(HashMap<String, Object> initValue)
    {

        int primaryKey = adip.joinThis(initValue);
        return primaryKey;

    }

    public List<HashMap<String, Object>> queryActivityList(HashMap<String, Object> initValues)
    {

        List<HashMap<String, Object>> result = adip.queryActivityList(initValues);
        new TimeService().isExpire(result);
        distanceService.addDistance(result, initValues);    
        return result;
    }

    public List<HashMap<String, Object>> getDetailedMessage(int aid)
    {
        List<HashMap<String, Object>> result = adip.getDetailedMessage(aid);
       
        return result;
    }

    public int supportThis(HashMap<String, Object> initValues)
    {

        int primaryKey = adip.supportThis(initValues);
        return primaryKey;
    }

    public List<HashMap<String, Object>> getDetailJoin(int aid)
    {
        List<HashMap<String, Object>> result = adip.getDetailedJoin(aid);
      //  List<User> users = beanUtils.setPropertiesFromList(result, User.class.getName());

        return result;

    }

    public List<HashMap<String, Object>> getDetailSupport(int aid)
    {
        List<HashMap<String, Object>> result = adip.getDetailedJoin(aid);
       // List<User> users = beanUtils.setPropertiesFromList(result, User.class.getName());
        return result;
    }

    public int commentThis(HashMap<String, Object> initValues)
    {

        new TimeService().addCreateTime(initValues);
        int flag = adip.commentThis(initValues);
        return flag;
    }
}